define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog0/index',
                    add_url: 'aps/planlog0/add',
                    edit_url: 'aps/planlog0/edit',
                    del_url: 'aps/planlog0/del',
                    multi_url: 'aps/planlog0/multi',
                    table: 'aps_planlog0',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'workorder_id', title: __('Workorder_id')},
                        {field: 'procedure1_id', title: __('Procedure1_id')},
                        {field: 'procedure2_id', title: __('Procedure2_id')},
                        {field: 'procedure3_id', title: __('Procedure3_id')},
                        {field: 'procedure4_id', title: __('Procedure4_id')},
                        {field: 'procedure5_id', title: __('Procedure5_id')},
                        {field: 'procedure6_id', title: __('Procedure6_id')},
                        {field: 'procedure1_man_id', title: __('Procedure1_man_id')},
                        {field: 'procedure2_man_id', title: __('Procedure2_man_id')},
                        {field: 'procedure3_man_id', title: __('Procedure3_man_id')},
                        {field: 'procedure4_man_id', title: __('Procedure4_man_id')},
                        {field: 'procedure5_man_id', title: __('Procedure5_man_id')},
                        {field: 'procedure6_man_id', title: __('Procedure6_man_id')},
                        {field: 'procedure1_finishdate', title: __('Procedure1_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure2_finishdate', title: __('Procedure2_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure3_finishdate', title: __('Procedure3_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure4_finishdate', title: __('Procedure4_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure5_finishdate', title: __('Procedure5_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure6_finishdate', title: __('Procedure6_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'workorder_finishdate', title: __('Workorder_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure1_startdate', title: __('Procedure1_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure2_startdate', title: __('Procedure2_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure3_startdate', title: __('Procedure3_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure4_startdate', title: __('Procedure4_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure5_startdate', title: __('Procedure5_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure6_startdate', title: __('Procedure6_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure1_manhours', title: __('Procedure1_manhours'), operate:'BETWEEN'},
                        {field: 'procedure2_manhours', title: __('Procedure2_manhours'), operate:'BETWEEN'},
                        {field: 'procedure3_manhours', title: __('Procedure3_manhours'), operate:'BETWEEN'},
                        {field: 'procedure4_manhours', title: __('Procedure4_manhours'), operate:'BETWEEN'},
                        {field: 'procedure5_manhours', title: __('Procedure5_manhours'), operate:'BETWEEN'},
                        {field: 'procedure6_manhours', title: __('Procedure6_manhours'), operate:'BETWEEN'},
                        {field: 'finishnum', title: __('Finishnum')},
                        {field: 'maxnum', title: __('Maxnum')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'procedure7_id', title: __('Procedure7_id')},
                        {field: 'procedure7_man_id', title: __('Procedure7_man_id')},
                        {field: 'procedure7_finishdate', title: __('Procedure7_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure7_startdate', title: __('Procedure7_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure7_manhours', title: __('Procedure7_manhours'), operate:'BETWEEN'},
                        {field: 'procedure8_id', title: __('Procedure8_id')},
                        {field: 'procedure8_man_id', title: __('Procedure8_man_id')},
                        {field: 'procedure8_finishdate', title: __('Procedure8_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure8_startdate', title: __('Procedure8_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure8_manhours', title: __('Procedure8_manhours'), operate:'BETWEEN'},
                        {field: 'sjwg', title: __('Sjwg'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'state', title: __('State'), searchList: {"未完成":__('未完成'),"已完成":__('已完成')}, formatter: Table.api.formatter.normal},
                        {field: 'jhwg', title: __('Jhwg'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});